﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;

namespace Utils
{
    static public class ExtensionMethods
    {
        static public int ToInt32(this object input)
        {
            return Convert.ToInt32(input);
        }

        static public DateTime ToDateTime(this object input)
        {
            return Convert.ToDateTime(input);
        }

        static public bool IsEmptyString(this string input)
        {
            return ((input == "") || (input == string.Empty));
        }

        static public bool IsLengthBetween(this string input, int min, Nullable<int> max = null)
        {
            bool r = true;

            if (max != null) r = ((input.Length >= min) && (input.Length <= max));
            else r = (input.Length >= min);

            return r;
        }

        static public bool IsBetween(this int input, int min, Nullable<int> max = null)
        {
            bool r = true;

            if (max != null) r = ((input >= min) && (input <= max));
            else r = (input >= min);

            return r;
        }

        static public bool IsValidEmail(this string input)
        {
            bool result = true;

            try
            {
                MailAddress mail = new MailAddress(input);
            }
            catch (FormatException)
            {
                result = false;
            }

            return result;
        }
    }
}
